<meta charset="UTF-8">

<div  style="height: 100%; overflow: auto">
	<form class="form-horizontal" style="padding-top: 18px">
		<div class="form-group"
			style="width: 1100px; height: 40px; margin-bottom: 0px">
			<div class="col-md-3">
				<span class='h3'>班级成绩录入<small>ClassGrade</small></span>
			</div>
			<label class="col-md-1 control-label">选择班级</label>
			<div class="col-md-2">
				<input class="form-control" type="text" name="bjSel" id="bjSel" value="" />
			</div>
			<label class="col-md-1 control-label">选择课程</label>
			<div class="col-md-2">
				<input class="form-control" type="text" name="kcSel" id="kcSel" value="" />
			</div>
			<button type="button" onclick="cx()" class="btn btn-default col-md-1"><span class="glyphicon glyphicon-search"></span> 查询</button>
		</div>
	</form>
	<hr>
	<div id='aa' style="display: none">
		<table id="mytable"></table>
	</div>
	
	<script type="text/javascript">
		$(function(){
			$('#bjSel').combobox({
				url:'tbclass/list',
				textField: 'name',
				valueField: 'id',
				hidebtn:function(){
					$('#aa').hide();
				},
				onchange:function(newsel){
					$('#aa').hide();
				}
			})
			
			$('#kcSel').combobox({
				url:'course/list',
				textField: 'name',
				valueField: 'id',
				hidebtn:function(){
					$('#aa').hide();
				},
				onchange:function(newsel){
					$('#aa').hide();
				}
		
			})
		})
		
	function shuaxin(bjId,kcId){
			$('#mytable').datagrid({
				url:'page?bjId='+bjId+"&kcId="+kcId,
				path:'grade',
				search:false, 
				showColumns:false, 
				showRefresh: false,  
				showToggle: false,
				columns:[
					[
						{title:'学号',field:'stuNo',formatter:function(value,row,index){
		            		return row.student.stuNo;}
						},
						{title:'姓名',field:'name',formatter:function(value,row,index){
		            		return row.student.name;}},
						{title:'成绩',field:'grade',width:300,formatter:function(value,row,index){
							if(!row.grade){
								row.grade=0;
							}
						   return '<input style="height:25px" onchange="xg('+row.id+',this)" class="form-control"  name="ipt" value="'+row.grade+'"/>'
						}}
					]		
				],
				buttons:[]
			})
	}
		
	function cx(){
			var bjId=$('#bjSel').combobox('getValue');
			var kcId=$('#kcSel').combobox('getValue');
			if(bjId==""||kcId==""){
				return;
			}
			$('#aa').text('');
			var table=$('<table id="mytable"/>')
			table.appendTo($('#aa'));
			shuaxin(bjId,kcId);
			$('#aa').show();
	}
	
	function xg(id,obj){
		grade=$(obj).val();
		if(!(/^[0-9]\d*$/.test(grade))){
			bootbox.alert('请输入正整数');
			return;
		};
	$.post('grade/classCjxg',{id:id,grade:grade},function(data){
			if(data.success){
				$.messagebox(data.msg,2000);
			}else{
				bootbox.alert(data.msg);
			}
		});
	}
	</script>
</div>